package work.extend;

/** 测试父子类同名成员变量 */
public class TestSameName {
    public static void main(String[] args) {
        Father1 f = new Son1();
        System.out.println("f.x:"+f.x);
        Son1 s = (Son1)f;
        System.out.println("s.x:"+s.x);
    }
}

class Father1 {

    int x = 10;

    public Father1() {
        this.print();
        x = 20;
    }

    public void print() {
        System.out.println("Father1.x = " + x);
    }
}

class Son1 extends Father1 {

    int x = 30;

    public Son1() {
        super();
        this.print();
        x = 40;
    }

    public void print() {
        System.out.println("Son1.x = " + x);
    }
}
